#ifndef SERVER_H
#define SERVER_H

#include <sys/select.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>

#include "protocol.h"

#define MAX_CLIENTS 4
#ifndef PORT
#define PORT 8852
#endif
#define MAX(x,y) x > y ? x : y

extern Player* players[MAX_CLIENTS];
extern Room** rooms;
extern int numRooms;
extern int numClients;
extern fd_set rfd;

void buildRooms(int num);
void readUserName(Player*);
void joinPlayerToRoom(Player*);
void removePlayerFromRoom(Player* ply, int id);
void connectionLost(Player*);
Player* getPlayer(int);
void playerQuit(Player*);
void sendRoom(Room*, Player*);
void sendRooms(Player*);
void sendPlayers(Player*);
void sendPlayer(Player*, Player*);
void sendMove(CODE, int);
int checkForWinner(int, int);
void sendWinner(int, int);
void resetRoom(int r);
void kickAllFromRoom(int r);

#endif
